# -*- coding: utf-8 *-*

#   This file is part of Sql-Rice.
#
#    Sql-Rice is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 3 of the License, or
#    (at your option) any later version.
#
#    Sql-Rice is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Sql-Rice; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

import window
import text_widget
import gui.backend.base as base
import db


_widgets = {base.DATE: text_widget.TextWidget,
        base.TEXT: text_widget.TextWidget,
        base.NUMBER: text_widget.TextWidget,
        base.ENUM: text_widget.TextWidget}


default_layout = None


def create_window(ricer, connect_to):
    win = window.Window()
    win.set_layout(None)
    for widget_info in ricer.widgets:
        W = _widgets[widget_info.widget]
        widget = W(widget_info, win)
        win.add_widget(widget)
    for param in ricer.sentence.params:
        win.actions.add_param(param)
    sql = {'select': ricer.sentence.sql,
            'insert': ricer.sentence.insert_query,
            'delete': ricer.sentence.delete_query,
            'update': ricer.sentence.update_query}
    dbset = db.DBSET(sql, connect_to, 'sqlite3')
    win.actions.add_action('search', dbset.search)
    win.actions.add_action('update', dbset.update)
    win.actions.add_action('delete', dbset.delete)
    win.actions.add_action('add', dbset.new)
    return win
